{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-09-12T06:44:28.080764Z",
     "start_time": "2025-09-12T06:44:13.693429Z"
    }
   },
   "source": [
    "import os, sys, torch\n",
    "os.chdir(r\"D:\\Data\\Project\\PythonProject\\MemeCLIP-main\\MemeCLIP-main\\code\")  # ←改成你的根目录\n",
    "sys.path.append(\".\")\n",
    "print(f\"CWD = {os.getcwd()}\")\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CWD = D:\\Data\\Project\\PythonProject\\MemeCLIP-main\\MemeCLIP-main\\code\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-03T08:19:34.831907Z",
     "start_time": "2025-06-03T08:19:34.826129Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import importlib, configs\n",
    "importlib.reload(configs)   # 让解释器重新读取文件\n",
    "from configs import cfg\n",
    "import torch\n",
    "cfg.multi_label = True                     # 关键开关\n",
    "cfg.class_names = [\n",
    "    'No Finding','Enlarged Cardiomediastinum','Cardiomegaly','Lung Opacity',\n",
    "    'Lung Lesion','Edema','Consolidation','Pneumonia','Atelectasis',\n",
    "    'Pneumothorax','Pleural Effusion','Pleural Other','Fracture'\n",
    "]\n",
    "cfg.num_classes = len(cfg.class_names)\n",
    "\n",
    "print(\"num_classes:\", cfg.num_classes)\n",
    "print(\"class_names:\", cfg.class_names[:3], \"...\")\n"
   ],
   "id": "5b8521b8ddc3f1bc",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "num_classes: 13\n",
      "class_names: ['No Finding', 'Enlarged Cardiomediastinum', 'Cardiomegaly'] ...\n"
     ]
    }
   ],
   "execution_count": 82
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-03T08:19:34.877361Z",
     "start_time": "2025-06-03T08:19:34.870506Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import importlib, datasets\n",
    "importlib.reload(datasets)   # 让解释器重新读取文件\n",
    "   # 让解释器重新读取文件\n"
   ],
   "id": "fe885e9a77411e14",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<module 'datasets' from 'D:\\\\Data\\\\Project\\\\PythonProject\\\\MemeCLIP-main\\\\MemeCLIP-main\\\\code\\\\datasets.py'>"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 83
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-03T08:19:34.930961Z",
     "start_time": "2025-06-03T08:19:34.922104Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#test\n",
    "import pandas as pd\n",
    "df = pd.read_csv(cfg.info_file, nrows=0)   # 只读表头\n",
    "print(df.columns.tolist())"
   ],
   "id": "a42958ab77de842a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Path', 'No Finding', 'Enlarged Cardiomediastinum', 'Cardiomegaly', 'Lung Opacity', 'Lung Lesion', 'Edema', 'Consolidation', 'Pneumonia', 'Atelectasis', 'Pneumothorax', 'Pleural Effusion', 'Pleural Other', 'Fracture', 'report', 'split']\n"
     ]
    }
   ],
   "execution_count": 84
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-03T08:19:35.596892Z",
     "start_time": "2025-06-03T08:19:34.957117Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from datasets import load_dataset, Custom_Collator\n",
    "\n",
    "dataset = load_dataset(cfg, split=\"train\")\n",
    "print(\"Dataset length:\", len(dataset))\n",
    "import pandas as pd\n",
    "df = pd.read_csv(cfg.info_file, nrows=5)\n",
    "print(df[cfg.class_names].dtypes)   # 应全部是 float32 / int\n",
    "print(df[cfg.class_names].head(2))\n",
    "sample = dataset[0]\n",
    "sample = dataset[0]\n",
    "print(sample['label'], sample['label'].dtype)      # tensor([...]) torch.float32\n",
    "print(sample['label'].shape)                      # torch.Size([13])\n",
    "\n",
    "print(\"label vec:\", sample[\"label\"], \"shape:\", sample[\"label\"].shape)\n",
    "\n",
    "assert sample[\"label\"].dtype == torch.float32, \"label dtype 应为 float32\"\n",
    "assert sample[\"label\"].shape[-1] == cfg.num_classes\n"
   ],
   "id": "73b77040252cf29c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataset length: 3200\n",
      "No Finding                    float64\n",
      "Enlarged Cardiomediastinum    float64\n",
      "Cardiomegaly                  float64\n",
      "Lung Opacity                  float64\n",
      "Lung Lesion                   float64\n",
      "Edema                         float64\n",
      "Consolidation                 float64\n",
      "Pneumonia                     float64\n",
      "Atelectasis                   float64\n",
      "Pneumothorax                  float64\n",
      "Pleural Effusion              float64\n",
      "Pleural Other                 float64\n",
      "Fracture                      float64\n",
      "dtype: object\n",
      "   No Finding  Enlarged Cardiomediastinum  Cardiomegaly  Lung Opacity  \\\n",
      "0         NaN                         NaN           NaN           1.0   \n",
      "1         NaN                         NaN           NaN           NaN   \n",
      "\n",
      "   Lung Lesion  Edema  Consolidation  Pneumonia  Atelectasis  Pneumothorax  \\\n",
      "0          NaN    NaN           -1.0        NaN         -1.0           NaN   \n",
      "1          NaN    1.0            NaN        NaN          NaN           NaN   \n",
      "\n",
      "   Pleural Effusion  Pleural Other  Fracture  \n",
      "0               NaN            NaN       NaN  \n",
      "1               NaN            NaN       NaN  \n",
      "tensor([0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) torch.float32\n",
      "torch.Size([13])\n",
      "label vec: tensor([0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) shape: torch.Size([13])\n"
     ]
    }
   ],
   "execution_count": 85
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-03T08:26:18.064279Z",
     "start_time": "2025-06-03T08:26:18.058095Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os, sys, torch, pprint\n",
    "print(\"Python exe :\", sys.executable)\n",
    "print(\"Torch path :\", torch.__file__)      # 真·PyTorch应在  .../site-packages/torch/__init__.py\n",
    "print(\"Has torch.version ?\", hasattr(torch, \"version\"))\n"
   ],
   "id": "b78c9eeaff65d15e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python exe : D:\\Data\\Anconda\\envs\\py3.12_pytorch\\python.exe\n",
      "Torch path : D:\\Data\\Anconda\\envs\\py3.12_pytorch\\Lib\\site-packages\\torch\\__init__.py\n",
      "Has torch.version ? False\n"
     ]
    }
   ],
   "execution_count": 87
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-03T08:20:44.921140Z",
     "start_time": "2025-06-03T08:20:44.128225Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from torch.utils.data import DataLoader\n",
    "from MemeCLIP import create_model\n",
    "\n",
    "loader = DataLoader(dataset, batch_size=2,\n",
    "                    collate_fn=Custom_Collator(cfg), shuffle=False)\n",
    "\n",
    "batch = next(iter(loader))\n",
    "print(\"image_features:\", batch[\"image_features\"].shape)\n",
    "print(\"labels:\", batch[\"labels\"].shape, batch[\"labels\"][0])\n",
    "\n",
    "model = create_model(cfg).eval().cuda()\n",
    "\n",
    "with torch.no_grad():\n",
    "    out = model.common_step(batch)   # 直接调用 common_step\n",
    "print(\"loss =\", out[\"loss\"].item())\n"
   ],
   "id": "b5546e5e78ac3b1a",
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "module 'torch' has no attribute 'version'",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mAttributeError\u001B[0m                            Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[86], line 2\u001B[0m\n\u001B[0;32m      1\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mtorch\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mutils\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mdata\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m DataLoader\n\u001B[1;32m----> 2\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mMemeCLIP\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m create_model\n\u001B[0;32m      4\u001B[0m loader \u001B[38;5;241m=\u001B[39m DataLoader(dataset, batch_size\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m2\u001B[39m,\n\u001B[0;32m      5\u001B[0m                     collate_fn\u001B[38;5;241m=\u001B[39mCustom_Collator(cfg), shuffle\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mFalse\u001B[39;00m)\n\u001B[0;32m      7\u001B[0m batch \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mnext\u001B[39m(\u001B[38;5;28miter\u001B[39m(loader))\n",
      "File \u001B[1;32mD:\\Data\\Project\\PythonProject\\MemeCLIP-main\\MemeCLIP-main\\code\\MemeCLIP.py:1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mpytorch_lightning\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mpl\u001B[39;00m\n\u001B[0;32m      2\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mtorch\u001B[39;00m\n\u001B[0;32m      3\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mtorch\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mnn\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mnn\u001B[39;00m\n",
      "File \u001B[1;32mD:\\Data\\Anconda\\envs\\py3.12_pytorch\\Lib\\site-packages\\pytorch_lightning\\__init__.py:25\u001B[0m\n\u001B[0;32m     22\u001B[0m     _logger\u001B[38;5;241m.\u001B[39maddHandler(logging\u001B[38;5;241m.\u001B[39mStreamHandler())\n\u001B[0;32m     23\u001B[0m     _logger\u001B[38;5;241m.\u001B[39mpropagate \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mFalse\u001B[39;00m\n\u001B[1;32m---> 25\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mutilities\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mseed\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m seed_everything  \u001B[38;5;66;03m# noqa: E402\u001B[39;00m\n\u001B[0;32m     26\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mutilities\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mwarnings\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m disable_possible_user_warnings  \u001B[38;5;66;03m# noqa: E402\u001B[39;00m\n\u001B[0;32m     27\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mpytorch_lightning\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mcallbacks\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m Callback  \u001B[38;5;66;03m# noqa: E402\u001B[39;00m\n",
      "File \u001B[1;32mD:\\Data\\Anconda\\envs\\py3.12_pytorch\\Lib\\site-packages\\lightning_fabric\\__init__.py:35\u001B[0m\n\u001B[0;32m     31\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m sys\u001B[38;5;241m.\u001B[39mplatform \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mwin32\u001B[39m\u001B[38;5;124m\"\u001B[39m:\n\u001B[0;32m     32\u001B[0m     os\u001B[38;5;241m.\u001B[39menviron[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mUSE_LIBUV\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m0\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m---> 35\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mfabric\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m Fabric  \u001B[38;5;66;03m# noqa: E402\u001B[39;00m\n\u001B[0;32m     36\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mutilities\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mseed\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m seed_everything  \u001B[38;5;66;03m# noqa: E402\u001B[39;00m\n\u001B[0;32m     37\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mutilities\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mwarnings\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m disable_possible_user_warnings  \u001B[38;5;66;03m# noqa: E402\u001B[39;00m\n",
      "File \u001B[1;32mD:\\Data\\Anconda\\envs\\py3.12_pytorch\\Lib\\site-packages\\lightning_fabric\\fabric.py:40\u001B[0m\n\u001B[0;32m     38\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01maccelerators\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01maccelerator\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m Accelerator\n\u001B[0;32m     39\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mconnector\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m _PLUGIN_INPUT, _PRECISION_INPUT, _Connector, _is_using_cli\n\u001B[1;32m---> 40\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mloggers\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m Logger\n\u001B[0;32m     41\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mplugins\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m Precision  \u001B[38;5;66;03m# avoid circular imports: # isort: split\u001B[39;00m\n\u001B[0;32m     42\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mstrategies\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m (\n\u001B[0;32m     43\u001B[0m     DataParallelStrategy,\n\u001B[0;32m     44\u001B[0m     DeepSpeedStrategy,\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m     48\u001B[0m     XLAStrategy,\n\u001B[0;32m     49\u001B[0m )\n",
      "File \u001B[1;32mD:\\Data\\Anconda\\envs\\py3.12_pytorch\\Lib\\site-packages\\lightning_fabric\\loggers\\__init__.py:15\u001B[0m\n\u001B[0;32m     13\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mloggers\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mcsv_logs\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m CSVLogger  \u001B[38;5;66;03m# noqa: F401\u001B[39;00m\n\u001B[0;32m     14\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mloggers\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mlogger\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m Logger  \u001B[38;5;66;03m# noqa: F401\u001B[39;00m\n\u001B[1;32m---> 15\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mloggers\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mtensorboard\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m TensorBoardLogger  \u001B[38;5;66;03m# noqa: F401\u001B[39;00m\n",
      "File \u001B[1;32mD:\\Data\\Anconda\\envs\\py3.12_pytorch\\Lib\\site-packages\\lightning_fabric\\loggers\\tensorboard.py:31\u001B[0m\n\u001B[0;32m     29\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mutilities\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mrank_zero\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m rank_zero_only, rank_zero_warn\n\u001B[0;32m     30\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mutilities\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mtypes\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m _PATH\n\u001B[1;32m---> 31\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mlightning_fabric\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mwrappers\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m _unwrap_objects\n\u001B[0;32m     33\u001B[0m _TENSORBOARD_AVAILABLE \u001B[38;5;241m=\u001B[39m RequirementCache(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtensorboard\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m     34\u001B[0m _TENSORBOARDX_AVAILABLE \u001B[38;5;241m=\u001B[39m RequirementCache(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtensorboardX\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n",
      "File \u001B[1;32mD:\\Data\\Anconda\\envs\\py3.12_pytorch\\Lib\\site-packages\\lightning_fabric\\wrappers.py:33\u001B[0m\n\u001B[0;32m     31\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mtorch\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m Tensor\n\u001B[0;32m     32\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mtorch\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m nn \u001B[38;5;28;01mas\u001B[39;00m nn\n\u001B[1;32m---> 33\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mtorch\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01m_dynamo\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m OptimizedModule\n\u001B[0;32m     34\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mtorch\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mnn\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mmodules\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mmodule\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m _IncompatibleKeys\n\u001B[0;32m     35\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mtorch\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01moptim\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m Optimizer\n",
      "File \u001B[1;32mD:\\Data\\Anconda\\envs\\py3.12_pytorch\\Lib\\site-packages\\torch\\_dynamo\\__init__.py:2\u001B[0m\n\u001B[0;32m      1\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mtorch\u001B[39;00m\n\u001B[1;32m----> 2\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m convert_frame, eval_frame, resume_execution\n\u001B[0;32m      3\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mbackends\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mregistry\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m list_backends, lookup_backend, register_backend\n\u001B[0;32m      4\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mcallback\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m callback_handler, on_compile_end, on_compile_start\n",
      "File \u001B[1;32mD:\\Data\\Anconda\\envs\\py3.12_pytorch\\Lib\\site-packages\\torch\\_dynamo\\convert_frame.py:48\u001B[0m\n\u001B[0;32m     45\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mtorch\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mutils\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01m_python_dispatch\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m _disable_current_modes\n\u001B[0;32m     46\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mtorch\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mutils\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01m_traceback\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m format_traceback_short\n\u001B[1;32m---> 48\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m config, exc, trace_rules\n\u001B[0;32m     49\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mbackends\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mregistry\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m CompilerFn\n\u001B[0;32m     50\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mbytecode_analysis\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m remove_dead_code, remove_pointless_jumps\n",
      "File \u001B[1;32mD:\\Data\\Anconda\\envs\\py3.12_pytorch\\Lib\\site-packages\\torch\\_dynamo\\config.py:101\u001B[0m\n\u001B[0;32m     98\u001B[0m allow_ignore_mark_dynamic \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mFalse\u001B[39;00m\n\u001B[0;32m    100\u001B[0m \u001B[38;5;66;03m# Set this to False to assume nn.Modules() contents are immutable (similar assumption as freezing)\u001B[39;00m\n\u001B[1;32m--> 101\u001B[0m guard_nn_modules \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mFalse\u001B[39;00m \u001B[38;5;28;01mif\u001B[39;00m \u001B[43mis_fbcode\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m \u001B[38;5;28;01melse\u001B[39;00m \u001B[38;5;28;01mTrue\u001B[39;00m\n\u001B[0;32m    103\u001B[0m \u001B[38;5;66;03m# Uses CPython internal dictionary tags to detect mutation. There is some\u001B[39;00m\n\u001B[0;32m    104\u001B[0m \u001B[38;5;66;03m# overlap between guard_nn_modules_using_dict_tags and guard_nn_modules flag.\u001B[39;00m\n\u001B[0;32m    105\u001B[0m \u001B[38;5;66;03m# guard_nn_modules unspecializes the nn module instance and adds guard for each\u001B[39;00m\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m    113\u001B[0m \u001B[38;5;66;03m# TODO(janimesh, voz): Remove both of these flags (or atleast guard_nn_modules)\u001B[39;00m\n\u001B[0;32m    114\u001B[0m \u001B[38;5;66;03m# once we have reached stability for the guard_nn_modules_using_dict_tags.\u001B[39;00m\n\u001B[0;32m    115\u001B[0m guard_nn_modules_using_dict_tags \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mTrue\u001B[39;00m\n",
      "File \u001B[1;32mD:\\Data\\Anconda\\envs\\py3.12_pytorch\\Lib\\site-packages\\torch\\_dynamo\\config.py:15\u001B[0m, in \u001B[0;36mis_fbcode\u001B[1;34m()\u001B[0m\n\u001B[0;32m     14\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21mis_fbcode\u001B[39m():\n\u001B[1;32m---> 15\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28mhasattr\u001B[39m(\u001B[43mtorch\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mversion\u001B[49m, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mgit_version\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n",
      "File \u001B[1;32mD:\\Data\\Anconda\\envs\\py3.12_pytorch\\Lib\\site-packages\\torch\\__init__.py:2216\u001B[0m, in \u001B[0;36m__getattr__\u001B[1;34m(name)\u001B[0m\n\u001B[0;32m   2213\u001B[0m     \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21;01mimportlib\u001B[39;00m\n\u001B[0;32m   2214\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m importlib\u001B[38;5;241m.\u001B[39mimport_module(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m.\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mname\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;18m__name__\u001B[39m)\n\u001B[1;32m-> 2216\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mAttributeError\u001B[39;00m(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mmodule \u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;18m__name__\u001B[39m\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m has no attribute \u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mname\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n",
      "\u001B[1;31mAttributeError\u001B[0m: module 'torch' has no attribute 'version'"
     ]
    }
   ],
   "execution_count": 86
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
